package Graphique;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
import java.util.ArrayList;

import javax.swing.*;

import Serveur.Twouit;
import Serveur.Utilisateur;

import Client.Client;

public class FilActualite extends JFrame{
	private static final long serialVersionUID = 1L;
	private JLabel intro = new JLabel();
	private JList jlist = new JList();
	private JComboBox jComboBox = new JComboBox();
	
	private JButton retwouitter = new JButton("Retwouitter");
	
	private ActionListenerChoix alc = new ActionListenerChoix();
	
	private Client c;

	public FilActualite(Client c, String titre, ArrayList l){
		super("Votre fil d'actualité");
		
		this.c = c;
		
		this.setSize(250, 250);
		
		intro.setText(titre);
		
		DefaultListModel model = new DefaultListModel();
		
		DefaultComboBoxModel  mdc = new DefaultComboBoxModel();
		jComboBox.setModel(mdc);
		
		retwouitter.addActionListener(alc);
		
		getContentPane().setLayout(new GridLayout(1,3));
		JPanel jp = new JPanel();
		jp.add(intro);
		jp.add(jComboBox);
		jp.add(retwouitter);
		jp.setLayout(new GridLayout(l.size(), 1));
		
		for (int i = 0; i < l.size(); i++){
				Twouit t = (Twouit) l.get(i);
				jComboBox.addItem(t);
		}			
		
		this.add(jp);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
		this.pack();
		
	}
	
	private class ActionListenerChoix implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			Object obj = e.getSource();
			
			if(retwouitter.equals(obj)){
				try {
					c.retwouitter((Twouit)jComboBox.getSelectedItem());
					dispose();
				} catch (RemoteException e1) {
					e1.printStackTrace();
				}
			}
		}
	}
}
